<template>
  <div>
    <!-- 接收借口获取的数据 -->
    <el-table :data="userlist" border style="width: 100%">
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="username" label="用户名称" width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            <el-tag v-if="item.row.status == 1">启用</el-tag>
            <el-tag v-else type="danger">禁用</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <!-- 获得每一行的数据 {{item.row}}-->
        <template slot-scope="item">
          <div>
            <el-button
              type="primary"
              icon="el-icon-edit"
              circle
              size="mini"
              @click="edit(item.row.uid)"
            ></el-button>
            <el-button
              @click="del(item.row.uid)"
              type="danger"
              size="mini"
              icon="el-icon-delete"
              circle
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      :page-size="size"
      background
      layout="prev, pager, next"
      :total="count"
      @current-change='changePage'
    >
    </el-pagination>
  </div>
</template>
<script>
// 引入封装好的辅助型函数
import { mapGetters, mapActions } from "vuex";
import { userDel } from "../../util/request/api";
export default {
  data() {
    return {
      // tableData: [],
    };
  },
  computed: {
    ...mapGetters({
      userlist: "manger/getUserList",
      size: "manger/getSize",
      count: "manger/getCount",

    }),
  },
  mounted() {
    // 组件加载时获取列表
    // menuList().then((res) => {
    //   console.log(res, "菜单列表 ");
    //   // 如果通过，那么就获取数据库里的列表
    //   if (res.code == 200) {
    //     this.tableData = res.list;
    //   }
    // });
    //
    this.getUserlist();
    // 总条数
    this.getCount();
  },

  methods: {
    changePage(n){
console.log(n,'n');
// 切换页面时候换页
this.changePageAction(n)
    },
    ...mapActions({
      getUserlist: "manger/getUserAction",
      getCount: "manger/getCountAction",
      changePageAction: "manger/changePageAction",
           
     
    }),
    //   编辑事件
    edit(id) {
      this.$emit("edit", id);
    },
    // 删除列表
    del(uid) {
      this.$confirm("此操作将删除该行信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        userDel({ uid })
          .then((res) => {
            if (res.code == 200) {
              // 重新调用列表,调用接口列表
              this.getUserlist();
              // 总条数
              this.getCount();
            } else {
              this.$message.error(res.msg);
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      });
    },
  },
};
</script>
<style scoped>
</style>